<template>
<div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <div class="common-form">{{$t('plus.free_shipping_setting')}}</div>

      <el-form-item :label="$t('plus.enable_free_shipping')">
        <div>
          <el-radio v-model="form.is_open" :label="1">{{$t('plus.enable')}}</el-radio>
          <el-radio v-model="form.is_open" :label="0">{{$t('plus.disable')}}</el-radio>
        </div>
      </el-form-item>
      <el-form-item
        :label="$t('plus.order_amount_reach')"
        prop="money"
        :rules="[{  required: true,  message: ' '}]"
      >
        <el-input
          v-model="form.money"
          type="number"
          style="width: 200px"
        ></el-input
        >{{$t('plus.unit_yuan')}} 
<div class="tips">{{$t('plus.free_shipping_tip')}}</div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading"
          >{{$t('plus.submit')}}</el-button
        >
      </div>
    </el-form>
  </div>
</template>

<script>
import SettingApi from "@/api/setting.js";
export default {
  data() {
    return {
      form: {
        is_open: "",
        money: ""
      },
      loading: false
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      let self = this;
      SettingApi.fullfreeDetail({}, true).then(res => {
        let vars = res.data;
        self.form.is_open = vars.is_open;
        self.form.money = vars.money;
      }).catch(error => {});
    },
    //提交表单
    onSubmit() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          SettingApi.editFullfree(params, true).then(data => {
            self.loading = false;
            ElMessage({
              message: $t("plus.setting_success"),
              type: "success"
            });
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

<style>
.tips {
  color: #ccc;
}
</style>

